<?php
App::import('lib', 'Optimiser');
class OptimiserController extends OptimiserAppController {

    var $name = 'Optimiser';
    var $uses = array();
    var $template = false;
    var $autoRender = false;
    private static $cacheConfigName = "optimiser_cache";

    public function js($token) {
        $wcode = Cache::read('optimiser-js-' . $token, self::$cacheConfigName);
        if ($wcode == null) {
            echo("Cache not found!");
        } else {
            header("Date: " . date("D, j M Y G:i:s ") . 'GMT');
            header("Content-Type: application/javascript");
            header("Expires: " . gmdate("D, d M Y H:i:s", time() + DAY) . " GMT");
            header("Cache-Control: max-age=86400, must-revalidate"); // HTTP/1.1
            header("Pragma: cache");        // HTTP/1.0
            echo($wcode);
        }
    }
    
    public function css($token) {
        $wcode = Cache::read('optimiser-css-' . $token, self::$cacheConfigName);
        if ($wcode == null) {
            echo("Cache not found!");
        } else {
            header("Date: " . date("D, j M Y G:i:s ") . 'GMT');
            header("Content-Type: text/css");
            header("Expires: " . gmdate("D, d M Y H:i:s", time() + DAY) . " GMT");
            header("Cache-Control: max-age=86400, must-revalidate"); // HTTP/1.1
            header("Pragma: cache");        // HTTP/1.0
            echo($wcode);
        }
    }
}
